package com.longrise.co.ui.home.widget;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.longrise.co.R;
import com.longrise.co.ui.carfiles.widget.AddPhotoDialog;
import com.longrise.co.utils.DensityUtil;

/**
 * Created by Administrator on 2017/10/26.
 */

public class AreaSelectDialog extends Dialog{
    private OnSelectAreaListener mListener;

    public static final int SELECT_HN = 0;//河南
    public static final int SELECT_ZJ = 1;//浙江

    public AreaSelectDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public AreaSelectDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    protected AreaSelectDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_area_select, null);
        setContentView(view);
        Button area1Name = (Button)view.findViewById(R.id.area1_name);
        Button area2Name = (Button)view.findViewById(R.id.area2_name);

        area1Name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onSelect(SELECT_HN);
            }
        });
        area2Name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onSelect(SELECT_ZJ);
            }
        });

        //设置点击事件
        //设置dialog大小，这里是一个小赠送，模块好的控件大小设置
        Window dialogWindow = getWindow();
        WindowManager manager = ((Activity) context).getWindowManager();
        WindowManager.LayoutParams params = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        dialogWindow.setGravity(Gravity.CENTER);//设置对话框位置
        params.width = DensityUtil.dip2px(context,300); // 宽度设置为屏幕的0.8，根据实际情况调整
        params.height = DensityUtil.dip2px(context,195);
        dialogWindow.setAttributes(params);
    }

    public void setOnSelectAreaListener(AreaSelectDialog.OnSelectAreaListener listener) {
        mListener = listener;
    }

    public interface OnSelectAreaListener {
        void onSelect(int type);
    }
}
